package com.SuanFa.ZuoChengYun;

import java.util.Arrays;

/**
 * 一个数组，一个num数，将数组分为左中右三个区域，分别存小于，等于，大于num的值
 */
public class a1 {
    public static void main(String[] args) {
        int num = 5;
        int[] nums={7,4,5,3,5,3,5,3,6,3,2,4,4,5,9,8};
        int [] numsNew=sortArr(nums,num);
        System.out.println(Arrays.toString(numsNew));
    }

    private static int[] sortArr(int[] nums, int num) {
        int i=0;
        int left=-1;
        int right=nums.length;
        while (i<nums.length&&i<=right-1){
            if (nums[i]<num){
                int temp=nums[i];
                nums[i]=nums[left+1];
                nums[left+1]=temp;
                left+=1;
                i++;
            }else if(nums[i]==num){
                i++;
            }else if(nums[i]>num){
                int temp=nums[i];
                nums[i]=nums[right-1];
                nums[right-1]=temp;
                right-=1;
            }
        }
        return nums;
    }
}
